
package com.suarte.core.hibernate;
import com.suarte.core.Company;
import com.suarte.core.dao.CompanyDao;
import java.util.ArrayList;
import java.util.List;

import org.appfuse.dao.hibernate.GenericDaoHibernate;

import org.springframework.stereotype.Repository;

/**
 * @date   Apr 07, 2011
 * @author Ggutierrez
 */
@Repository("companyDao")
public class CompanyDaoHibernate extends GenericDaoHibernate<Company, Long> implements CompanyDao {
    
    public CompanyDaoHibernate() {
        super(Company.class);
    }

    public List<Company> findCompanies() {
        return getHibernateTemplate().find("from Company this order by upper(this.description) asc");
    }

    public List<Company> findCompanies(String description) {
        String hql = "from Company this where 1 = 1";

        List args = new ArrayList();

        if (description != null) {
            args.add(description.concat("%"));
            hql += " and upper(this.description) like upper(?)";
        }
        
        List results = getHibernateTemplate().find(hql, args.toArray());
        return results;
    }
}
